package imserver.common.util;

import java.util.Random;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import imserver.service.MemberService;

/**
 * 随机生成用户账户
 * @author zhanghongbin01
 *
 */
@Service
public class GernateNum {
	
	@Resource
	private MemberService memberService;
	
	/**
	 * 随机生成9位用户账户
	 * @return
	 */
	private  String create(){
		StringBuffer strBuf = new StringBuffer();
		Random random = new Random();
		for(int i=0; i<9; i++){
			strBuf.append(""+random.nextInt(9));
		}
		return strBuf.toString();
	}
	
	/**
	 * 获取生成的账户
	 * @return
	 * @throws DaoException 
	 */
	public  String getMemberNum() throws DaoException{
		String memberNum = null;
		boolean isExists = true;
		while(isExists == true){
			memberNum  = create();
			isExists = memberService.exists(memberNum);
		}
		return memberNum;
	}
	
	
}
